<template>
	<view>
		<view class="news-item" @click="navigator(item.id)" v-for="(item, index) in list" :key="item.id">
			<image :src="item.img_url" mode=""></image>
			<view class="right">
				<view class="title">
					{{item.title}}
				</view>
				<view class="info">
					<!-- 全局定义过滤器 -->
					<text>发表时间：{{item.add_time | dataFormat()}}</text>
					<!-- 局部定义过滤器，组件内可以定义局部过滤器，保证其他地方调用也可以正常执行 -->
					<!-- <text>发表时间：{{item.add_time | formatData}}</text> -->
					<text>浏览次数：{{item.click}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props:['list'],
		filters:{
			formatData(data) {
				const dt = new Date(data)
				
				const y = dt.getFullYear()
				const m = (dt.getMonth() + 1 + '').padStart(2, '0')
				const d = (dt.getDate() + '').padStart(2, '0')
				
				const hh = (dt.getHours() + '').padStart(2, '0')
				const mm = (dt.getMinutes() + '').padStart(2, '0')
				const ss = (dt.getSeconds() + '').padStart(2, '0')
				
				return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
			}
		},
		data() {
			return {
				
			};
		},
		methods:{
			navigator(id) {
				this.$emit('itemClick',id)
			}
		}
	}
</script>

<style lang="scss">
	.news-item {
		display: flex;
		padding: 10rpx 20rpx;
		border-bottom: 1px solid $shop-color;
		image {
			min-width: 200rpx;
			max-width: 200rpx;
			height: 150rpx;
		}
		.right {
			margin-left: 15rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			.title {
				font-size: 30rpx;
			}
			.info {
				font-size: 24rpx;
				text:nth-child(2) {
					margin-left: 30rpx;
				}
			}
		}
	}
</style>
